/*
//Removing these aspects of counter-attacking for now, but I'm keeping them here in case I want to re-add them at a later point.
//Equipment
if (targetItems && targetItems.length > 0) {
for (var i = 0; i < targetItems.length; i++) {
var iFlags = targetItems[i].ScriptFlags;
if (iFlags.get("counter_attack") && !iFlags.get("cannot_counter")) {
if (!source || source.Dead || target.Dead) {
return;
}
if (eFlags.get("cannot_be_countered") || sFlags.get("cannot_be_countered")) {
return;
}
if (sourceItems && sourceItems.length > 0) {
for (var i = 0; i < sourceItems.length; i++) {
var item = sourceItems[i];
if (item.ScriptFlags.get("cannot_be_countered")) {
return;
}
}
}
if (source.Effects && source.Effects.length > 0) {
for (var i = 0; i < source.Effects.length; i++) {
var effect = source.Effects[i];
if (effect.ScriptFlags.get("cannot_be_countered")) {
return;
}
}
}
if (target.Effects && target.Effects.length > 0) {
for (var i = 0; i < target.Effects.length; i++) {
var effect = target.Effects[i];
if (effect.ScriptFlags.get("cannot_counter")) {
return;
}
}
}
if (iFlags.get("counter_attack_cost")) {
var caCost = iFlags.get("counter_attack_cost");
caCost = caCost.split(",");
for (var count = 0; count < caCost.length; count++) {
var split2 = caCost[count].split(":");
if (target.Points.get(split2[0])) {
var CPoint = target.Points.get(split2[0]);
if (!split2[1]) {
say("Error: If using the counter attack cost flag you must specify a cost!");
}
if (split2[1]) {
if (CPoint.Current < split2[1]) return;
if (CPoint.Current >= split2[1]) {
var subtract = split2[1];
CPoint.Current = (CPoint.Current - subtract);
shared.ShareUnitPointUpdate(target, [split2[0]]);
}
}
}
}
}
var counterAttack = iFlags.get("counter_attack");
var counterAttackChance = flags.get("counter_attack_chance");
var counterAttackRange = iFlags.get("counter_attack_range");
var random = counterAttack.split(",");
for (var i = 0; i < random.length; i++) {
random[i] = random[i].split(":");
}
if (!counterAttackChance) {
say("Error: You must supply a counter attack chance!");
}
if (!counterAttackRange) {
say("Error: You must supply a maximum range at which counter attacking can occur!");
}
if (counterAttackChance) {
var hasPercent = false;
if (counterAttackChance) hasPercent = true;
var work = true;
if (hasPercent) {
chance = parseInt(counterAttackChance);
if (chance <= 0) chance = 0;
if (chance >= 100) chance = 100;
if (shared.Calculate("1r100")>chance) work = false;
}
var range = false;
if (counterAttackRange) range = true;
if (range) {
var distance = shared.Map.GetDistance(source.Tile.X, source.Tile.Y, target.Tile.X, target.Tile.Y);
if (distance <= counterAttackRange) work = true;
}
if (work) {
if (flags.get("counter_attack_damage_points")) {
var pointToCounter = flags.get("counter_attack_damage_points");
pointToCounter = pointToCounter.split(",");
for (var c = 0; c < pointToCounter.length; c++) {
if (point.LookupName != pointToCounter[c]) return;
}
}
say("Counter attack!");
if (iFlags.get("counter_attack_sound")) {
randomSound(chooseFromARandomSelectString(iFlags.get("counter_attack_sound")));
}
if (iFlags.get("counter_attack_message")) {
var msg = chooseFromARandomSelectString(iFlags.get("counter_attack_message"));
say((msg).format(target.GetName(),source.GetName()));
}
for (var counter = 0; counter < random.length; counter++) {
//say(target.GetName() +" is definitely a bitch!");
target.DoDamageTo(source, random[counter][1], random[counter][0], random[counter][2]);
}
}
}
}
}
}

//Effects
if (target.Effects && target.Effects.length > 0) {
for (var p = 0; p < target.Effects.length; p++) {
var fxFlags = target.Effects[p].ScriptFlags;
if (fxFlags.get("counter_attack")) {
if (targetItems && targetItems.length > 0) {
for (var i = 0; i < targetItems.length; i++) {
var iFlags = targetItems[i].ScriptFlags;
if (iFlags.get("counter_attack") || iFlags.get("cannot_counter")) {
return; //It does not make sense to counter twice. Hopefully this will stop it.
}
}
}
if (target.PassiveSkils && target.PassiveSkills.length > 0) {
for (var i = 0; i < target.PassiveSkills.length; i++) {
var passiveSkill = target.PassiveSkills[i];
if (passiveSkill.ScriptFlags.get("counter_attack")) {
return;
}
}
}
if (!source || source.Dead || target.Dead) {
return;
}
if (eFlags.get("cannot_be_countered") || sFlags.get("cannot_be_countered")) {
return;
}
if (flags.get("counter_attack")) {
return; // to prevent multiple counters.
}
if (sourceItems && sourceItems.length > 0) {
for (var i = 0; i < sourceItems.length; i++) {
var item = sourceItems[i];
if (item.ScriptFlags.get("cannot_be_countered")) {
return;
}
}
}
if (source.Effects && source.Effects.length > 0) {
for (var i = 0; i < source.Effects.length; i++) {
var effect = source.Effects[i];
if (effect.ScriptFlags.get("cannot_be_countered")) {
return;
}
}
}
if (target.Effects && target.Effects.length > 0) {
for (var i = 0; i < target.Effects.length; i++) {
var effect = target.Effects[i];
if (effect.ScriptFlags.get("cannot_counter")) {
return;
}
}
}
if (fxFlags.get("counter_attack_cost")) {
var caCost = fxFlags.get("counter_attack_cost");
caCost = caCost.split(",");
for (var count = 0; count < caCost.length; count++) {
var split2 = caCost[count].split(":");
if (target.Points.get(split2[0])) {
var CPoint = target.Points.get(split2[0]);
if (!split2[1]) {
say("Error: If using the counter attack cost flag you must specify a cost!");
}
if (split2[1]) {
if (CPoint.Current < split2[1]) return;
if (CPoint.Current >= split2[1]) {
var subtract = split2[1];
CPoint.Current = (CPoint.Current - subtract);
shared.ShareUnitPointUpdate(target, [split2[0]]);
}
}
}
}
}
var counterAttack = fxFlags.get("counter_attack");
var counterAttackChance = flags.get("counter_attack_chance");
var counterAttackRange = fxFlags.get("counter_attack_range");
var random = counterAttack.split(",");
for (var i = 0; i < random.length; i++) {
random[i] = random[i].split(":");
}
if (!counterAttackChance) {
say("Error: You must supply a counter attack chance!");
}
if (!counterAttackRange) {
say("Error: You must supply a maximum range at which counter attacking can occur!");
}
if (counterAttackChance) {
var hasPercent = false;
if (counterAttackChance) hasPercent = true;
var work = true;
if (hasPercent) {
chance = parseInt(counterAttackChance);
if (chance <= 0) chance = 0;
if (chance >= 100) chance = 100;
if (shared.Calculate("1r100")>chance) work = false;
}
var range = false;
if (counterAttackRange) range = true;
if (range) {
var distance = shared.Map.GetDistance(source.Tile.X, source.Tile.Y, target.Tile.X, target.Tile.Y);
if (distance <= counterAttackRange) work = true;
}
if (work) {
for (var counter = 0; counter < random.length; counter++) {
if (!source.Points.get(random[counter][0])) {
return;
}
}
if (flags.get("counter_attack_damage_points")) {
var pointToCounter = flags.get("counter_attack_damage_points");
pointToCounter = pointToCounter.split(",");
for (var c = 0; c < pointToCounter.length; c++) {
if (point.LookupName != pointToCounter[c]) return;
}
}
say("Counter attack!");
if (fxFlags.get("counter_attack_sound")) {
randomSound(chooseFromARandomSelectString(flags.get("counter_attack_sound")));
}
if (fxFlags.get("counter_attack_message")) {
var msg = chooseFromARandomSelectString(fxFlags.get("counter_attack_message"));
say((msg).format(target.GetName(),source.GetName()));
}
for (var counter = 0; counter < random.length; counter++) {
//say(target.GetName() +" is definitely a bitch!");
target.DoDamageTo(source, random[counter][1], random[counter][0], random[counter][2]);
}
}
}
}
}
}
*/
